package com.neuedu.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.neuedu.bean.User;

public class MapExample {
	/**
	 * Map：键值对
	 *     应用：
	 */
	public static void main(String[] args) {
		Map<String,User> map=new HashMap<>();
		User user1=new User();
		user1.setUserid(111023);
		user1.setUsername("tom");
		user1.setUserpwd("123456");
		user1.setAge(18);
		
		map.put(user1.getUsername(),user1 );
		
		
		User user2=new User();
		user2.setUserid(111078);
		user2.setUsername("max");
		user2.setUserpwd("789456");
		user2.setAge(21);
		
		map.put(user2.getUsername(), user2);
		
	     Set<String> keys=	map.keySet();
	
	    for(String key:keys) {
	    	System.out.println(map.get(key));
	    }
	    
	    System.out.println("-------------------------");
	    
	    Set<Map.Entry<String, User>> entrySet = map.entrySet();
	    for(Map.Entry<String, User> m:entrySet) {
	    	System.out.println(m.getValue());
	    	System.out.println(m.getKey());
	    }
		
	}

}
